package com.sky.repository;

import com.sky.entity.Review;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface ReviewRepository extends MongoRepository<Review, String> {
    List<Review> findByuId(Integer uId);

    @Query("{ 'u_id': ?0, 'b_id': ?1 }")
    List<Review> findByuIdAndbId(Integer uId, String bId);

    @Query("{'status': ?0}")
    Page<Review> findByStatus(Integer status, Pageable pageable);

    @Query("UPDATE Review r SET r.status = :status, r.updateTime = :updateTime WHERE r.id IN :ids")
    void updateStatusByIds(@Param("ids") List<String> ids,
                           @Param("status") Integer status,
                           @Param("updateTime") Date updateTime);
}
